import 'package:flutter/material.dart';
import 'package:happy_elf_app/utils/adaption.dart';
import 'package:happy_elf_app/utils/color.dart';
import 'package:happy_elf_app/utils/globalKey.dart';
import 'package:happy_elf_app/widgets/Toast/index.dart';
import 'package:happy_elf_app/widgets/headerBack/index.dart';

class My extends StatefulWidget {
  const My({super.key});

  @override
  State<My> createState() => _MyState();
}

class _MyState extends State<My> with SingleTickerProviderStateMixin {
  late AnimationController _controller;

  List settingList = [
    {"title": "实验介绍", "page": 1},
    {"title": "必读内容", "page": 2},
    {"title": "精灵历程", "page": 3},
    {"title": "任务历程", "page": 4},
    {"title": "流程收藏", "page": 5},
  ];
  Map userInfo = {'name': "admin", "img": "", "target": "我想找一份符合心意的工作"}; //个人信息

  int activeIndex = 0;

  @override
  void initState() {
    super.initState();
    _controller = AnimationController(vsync: this);
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  Widget userBuild() {
    return Column(
      children: [
        ...settingList.map((e) => GestureDetector(
              onTap: () {
                if ([3, 4, 5].contains(e['page'])) {
                  Toast.show(
                      context: Global.navigatorKey.currentContext!,
                      message: '敬请期待~');
                } else {
                  activeIndex = 0;

                  Navigator.pushNamed(
                    context,
                    e['page'] == 1 ? 'Introduction' : 'Readme',
                  );
                }
                setState(() {
                  activeIndex = e['page'];
                });
              },
              child: Container(
                padding: EdgeInsets.symmetric(vertical: 20.0, horizontal: 16.0),
                margin: EdgeInsets.symmetric(vertical: 8),
                decoration: BoxDecoration(
                    boxShadow: [
                      BoxShadow(
                        color: Colors.grey.withOpacity(0.2),
                        spreadRadius: 0,
                        blurRadius: 2,
                        offset: Offset(0, 2), // changes position of shadow
                      ),
                    ],
                    color: hexColor(
                        activeIndex == e['page'] ? '#e9614d' : '#ffffff'),
                    borderRadius: BorderRadius.circular(10)),
                child: Row(
                  children: [
                    Text(
                      e['title'],
                      style: TextStyle(
                          color: hexColor(
                              activeIndex == e['page'] ? '#ffffff' : '#333333'),
                          fontSize: 16),
                    ),
                    Spacer(),
                    Icon(
                      Icons.arrow_forward_ios,
                      size: 16,
                      color: hexColor(
                          activeIndex == e['page'] ? '#ffffff' : '#8D8D8D'),
                    )
                  ],
                ),
              ),
            ))
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    final size = MediaQuery.of(context).size;
    return Container(
      color: hexColor('#ffffff'),
      child: Column(
        children: [
          HeaderBack(
            title: '个人主页',
            isFirst: false,
            callback: () {},
          ),
          Container(
            decoration:
                BoxDecoration(color: hexColor('#C6C6C6').withOpacity(0.3)),
            padding: EdgeInsets.symmetric(vertical: 24, horizontal: 16),
            child: Row(
              children: [
                Container(
                  width: 46,
                  height: 46,
                  margin: EdgeInsets.only(left: 24, right: 26),
                  alignment: Alignment.center,
                  decoration: BoxDecoration(
                      color: hexColor('#e9614d'),
                      borderRadius: BorderRadius.circular(30)),
                  child: userInfo['img'] != ''
                      ? Image.network(userInfo['img'])
                      : Text(
                          userInfo['name'][0],
                          style: TextStyle(
                              color: hexColor('#ffffff'), fontSize: 26),
                        ),
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(userInfo['name'],
                        style: TextStyle(
                            color: hexColor('#333333'),
                            fontSize: 18,
                            fontWeight: FontWeight.w500)),
                    SizedBox(height: 4),
                    Text(userInfo['target'],
                        style:
                            TextStyle(color: hexColor('#8D8D8D'), fontSize: 13))
                  ],
                )
              ],
            ),
          ),
          Container(
            color: hexColor('#ffffff'),
            padding: EdgeInsets.all(12),
            child: userBuild(),
          )
        ],
      ),
    );
  }
}
